﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using RT = Coolzon.Metadata.Runtime;

namespace Coolzon.UI.Core.Converters
{
    public class FontWeightConverter : ValueConverter
    {
        public object Convert(ConvertContext context, RT.Property property)
        {
            string strFontWeight = string.IsNullOrEmpty(property.ValueString) == false ? property.ValueString : property.ValueNode.GetAtrributeValue("Value");
            if (!string.IsNullOrEmpty(strFontWeight))
            {
                return (FontWeight)new System.Windows.FontWeightConverter().ConvertFromString(strFontWeight);
            }
            return null;
        }

        public RT.ValueNode ConvertBack(ConvertContext context, object value, object dtTagData)
        {
            RT.ValueNode valueNode = new RT.ValueNode("FontWeight");
            valueNode.Attributes = new Dictionary<string, string>();
            valueNode.Attributes.Add("Value", System.Convert.ToString(value));
            return valueNode;
        }
    }
}
